/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.facade.inventory;

import com.xtd.facade.AbstractFacade;
import com.xtd.model.inventory.PurchaseForm;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Lu Yuanbin
 */
@Stateless
public class PurchaseFormFacade extends AbstractFacade<PurchaseForm> {

    public PurchaseFormFacade() {
        super(PurchaseForm.class);
    }

    public List<PurchaseForm> findByContent(String content) {
        if (content == null) {
            content = "";
        }
        return getEntityManager().createQuery("select distinct o from PurchaseForm as o in(o.purchaseRecordCollection) as prc where o.number like :content and prc.number like :content and prc.name like :content").setParameter("content", "%" + content + "%").getResultList();
    }

    public PurchaseForm update(PurchaseForm purchaseForm) {
        if (purchaseForm.getId() == null) {
            purchaseForm.setNumber(generateNumber("CG", "PurchaseForm"));
            getEntityManager().persist(purchaseForm);
        } else {
            purchaseForm = getEntityManager().merge(purchaseForm);
        }
        return purchaseForm;
    }
}
